***************** Replication of Franchino, Fabio, and Camilla Mariotto. “Bargaining Outcomes and Success in EU Economic Governance Reforms”. Political Science Research and Methods.

* Step 1 to reproduce Figure 2

version 16

******************************* SENSITIVITY ANALYSIS  - Add Gaussian random noise to positions
*************   COMPUTING POINT PREDICTIONS: NBS - RP Nash bargaining solution with reference point
clear all
set obs 1
gen v = _n/10
save mad_NBSrp_noise.dta, replace

set seed 1234

local m =  1  /* iteration per each s.d. value */
while `m' <= 1000 {

local v = 0.1  /* v is s.d of Gaussian noise - s.d. of country and institutional positions is 41.74882 */
while `v' <= 42.1 {
* Upload original dataset
use NBSmodel_data.dta, clear
gen v = `v'
gen nbs_rp = 0
gen utility_star = .
gen utility = .
order utility utility_star nbs_rp

* Add Gaussian noise N(0,v) to Commission positions
generate random = rnormal(0,`v')
replace comm=comm+random
replace comm=100 if comm>100 
replace comm=0   if comm<0 

* Add Gaussian noise N(0,v) to Parliament positions
replace random = rnormal(0,`v')
replace ep_1=ep_1+random
replace ep_1=100 if ep_1>100 
replace ep_1=0   if ep_1<0 

* Add Gaussian noise N(0,v) to country positions
local j = 1
while `j' <= 27 {
replace random = rnormal(0,`v')
replace country`j'=country`j'+random if country`j'!=.
replace country`j'=100 if country`j'>100 
replace country`j'=0   if country`j'<0 
local j = `j' + 1
}

* Gradient ascent procedure
local i = 0
while `i' <= 100 {
replace utility =	salience1	* (sq-	country1	)^2 -	salience1	*(`i'-	country1	)^2 if	salience1	> 0 &	salience1	!= .
replace utility = utility/1000
replace utility = utility * (	salience2	* (sq-	country2	)^2 -	salience2	*(`i'-	country2	)^2) if	salience2	> 0 &	salience2	!= .
replace utility = utility/1000
replace utility = utility * (	salience3	* (sq-	country3	)^2 -	salience3	*(`i'-	country3	)^2) if	salience3	> 0 &	salience3	!= .
replace utility = utility/1000
replace utility = utility * (	salience4	* (sq-	country4	)^2 -	salience4	*(`i'-	country4	)^2) if	salience4	> 0 &	salience4	!= .
replace utility = utility/1000
replace utility = utility * (	salience5	* (sq-	country5	)^2 -	salience5	*(`i'-	country5	)^2) if	salience5	> 0 &	salience5	!= .
replace utility = utility/1000
replace utility = utility * (	salience6	* (sq-	country6	)^2 -	salience6	*(`i'-	country6	)^2) if	salience6	> 0 &	salience6	!= .
replace utility = utility/1000
replace utility = utility * (	salience7	* (sq-	country7	)^2 -	salience7	*(`i'-	country7	)^2) if	salience7	> 0 &	salience7	!= .
replace utility = utility/1000
replace utility = utility * (	salience8	* (sq-	country8	)^2 -	salience8	*(`i'-	country8	)^2) if	salience8	> 0 &	salience8	!= .
replace utility = utility/1000
replace utility = utility * (	salience9	* (sq-	country9	)^2 -	salience9	*(`i'-	country9	)^2) if	salience9	> 0 &	salience9	!= .
replace utility = utility/1000
replace utility = utility * (	salience10	* (sq-	country10	)^2 -	salience10	*(`i'-	country10	)^2) if	salience10	> 0 &	salience10	!= .
replace utility = utility/1000
replace utility = utility * (	salience11	* (sq-	country11	)^2 -	salience11	*(`i'-	country11	)^2) if	salience11	> 0 &	salience11	!= .
replace utility = utility/1000
replace utility = utility * (	salience12	* (sq-	country12	)^2 -	salience12	*(`i'-	country12	)^2) if	salience12	> 0 &	salience12	!= .
replace utility = utility/1000
replace utility = utility * (	salience13	* (sq-	country13	)^2 -	salience13	*(`i'-	country13	)^2) if	salience13	> 0 &	salience13	!= .
replace utility = utility/1000
replace utility = utility * (	salience14	* (sq-	country14	)^2 -	salience14	*(`i'-	country14	)^2) if	salience14	> 0 &	salience14	!= .
replace utility = utility/1000
replace utility = utility * (	salience15	* (sq-	country15	)^2 -	salience15	*(`i'-	country15	)^2) if	salience15	> 0 &	salience15	!= .
replace utility = utility/1000
replace utility = utility * (	salience16	* (sq-	country16	)^2 -	salience16	*(`i'-	country16	)^2) if	salience16	> 0 &	salience16	!= .
replace utility = utility/1000
replace utility = utility * (	salience17	* (sq-	country17	)^2 -	salience17	*(`i'-	country17	)^2) if	salience17	> 0 &	salience17	!= .
replace utility = utility/1000
replace utility = utility * (	salience18	* (sq-	country18	)^2 -	salience18	*(`i'-	country18	)^2) if	salience18	> 0 &	salience18	!= .
replace utility = utility/1000
replace utility = utility * (	salience19	* (sq-	country19	)^2 -	salience19	*(`i'-	country19	)^2) if	salience19	> 0 &	salience19	!= .
replace utility = utility/1000
replace utility = utility * (	salience20	* (sq-	country20	)^2 -	salience20	*(`i'-	country20	)^2) if	salience20	> 0 &	salience20	!= .
replace utility = utility/1000
replace utility = utility * (	salience21	* (sq-	country21	)^2 -	salience21	*(`i'-	country21	)^2) if	salience21	> 0 &	salience21	!= .
replace utility = utility/1000
replace utility = utility * (	salience22	* (sq-	country22	)^2 -	salience22	*(`i'-	country22	)^2) if	salience22	> 0 &	salience22	!= .
replace utility = utility/1000
replace utility = utility * (	salience23	* (sq-	country23	)^2 -	salience23	*(`i'-	country23	)^2) if	salience23	> 0 &	salience23	!= .
replace utility = utility/1000
replace utility = utility * (	salience24	* (sq-	country24	)^2 -	salience24	*(`i'-	country24	)^2) if	salience24	> 0 &	salience24	!= .
replace utility = utility/1000
replace utility = utility * (	salience25	* (sq-	country25	)^2 -	salience25	*(`i'-	country25	)^2) if	salience25	> 0 &	salience25	!= .
replace utility = utility/1000
replace utility = utility * (	salience26	* (sq-	country26	)^2 -	salience26	*(`i'-	country26	)^2) if	salience26	> 0 &	salience26	!= .
replace utility = utility/1000
replace utility = utility * (	salience27	* (sq-	country27	)^2 -	salience27	*(`i'-	country27	)^2) if	salience27	> 0 &	salience27	!= .
replace utility = utility/1000

* comm and ep positions (exclude if we want only country positions)
replace utility = utility * (	salience_comm	* (sq-	comm	)^2 -	salience_comm	*(`i'-	comm	)^2)
replace utility = utility/1000
replace utility = utility * (	salience_ep	* (sq-	ep_1	)^2 -	salience_ep	*(`i'-	ep_1	)^2) if	ep_rule==2
replace utility = utility/1000

replace utility_star = utility if `i'==0
replace nbs_rp = `i' if utility > utility_star
replace utility_star = utility if utility > utility_star

local i = `i' + 1
}

order utility utility_star nbs_rp sq outcome
sort act issue_id
label variable nbs_rp "nash bargaining solution, with reference point"
label variable utility_star "maximized product of actors' utilities" 

* Compute means of absolute differences between outcomes and model predictions
gen mad`m'=abs(nbs_rp-outcome)
collapse v mad`m'
label variable mad`m' "mean of absolute differences" 
label variable v "s.d of Gaussian noise" 

merge 1:1 v using mad_NBSrp_noise.dta, nogen
save mad_NBSrp_noise.dta, replace
sort v
pause 1000

       
local v = `v' + 1 /* increments of s.d. */
}

local m = `m' + 1 /* simulations */
}

egen NBSrp = rowmean(mad*)
label variable NBSrp "mean of absolute differences across m simulations" 
egen NBSrp_u = rowpctile(mad*), p(97.5)
label variable NBSrp_u "upper boundary" 
egen NBSrp_l = rowpctile(mad*), p(2.5)
label variable NBSrp_l "lower boundary" 

drop mad*
save mad_NBSrp_noise.dta, replace

exit

